package com.lv.service.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.service.R
import com.lv.service.bean.CommonSelectedBean

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 单选弹窗 选择器
 */
class RecyclerSelectedTag1Adapter(private val datas: MutableList<CommonSelectedBean>?) :
    BaseQuickAdapter<CommonSelectedBean, BaseViewHolder>
        (R.layout.item_selected_tag_1, datas) {
    override fun convert(holder: BaseViewHolder, item: CommonSelectedBean, payloads: List<Any>) {
        super.convert(holder, item, payloads)
        val ivSelected = holder.getView<ImageView>(R.id.iv_selected)
        val selected = item.selected
        ivSelected.setImageResource(if (selected) com.lv.common.R.drawable.ic_selected else com.lv.common.R.drawable.ic_unselected)

    }

    override fun convert(holder: BaseViewHolder, item: CommonSelectedBean) {
        val layoutPosition = holder.layoutPosition
        val clParent = holder.getView<ConstraintLayout>(R.id.cl_parent)
        val tvName = holder.getView<TextView>(R.id.tv_name)
        val ivSelected = holder.getView<ImageView>(R.id.iv_selected)
        val viewBottom = holder.getView<View>(R.id.view_bottom)
        tvName.text = item.name
        if (item.tag == "1") {
            ivSelected.setImageResource(com.lv.common.R.drawable.ic_unselected_gray)
        } else {
            val selected = item.selected
            ivSelected.setImageResource(if (selected) com.lv.common.R.drawable.ic_selected else com.lv.common.R.drawable.ic_unselected)
        }
        viewBottom.visibility = if (layoutPosition == datas!!.size - 1) View.GONE else View.VISIBLE

        clParent.setOnClickListener {
            onViewItemClickListener?.onClick(holder.layoutPosition, item)
        }
    }

    var onViewItemClickListener: OnPositionTListener<CommonSelectedBean>? = null

}